package com.usian.controller;

import com.usian.pojo.Dto;
import com.usian.pojo.Etc;
import com.usian.pojo.Role;
import com.usian.service.EtcService;
import com.usian.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("e")
public class EtcController {
    @Autowired
    private EtcService etcService;
    @Autowired
    private UserService userService;
    @RequestMapping("tologin")
    public String toLogin(){
        return "login";
    }
    //tozhu
    @RequestMapping("tozhu")
    public String tozhu(Model model){
        List<Role> role=etcService.findRole();
        model.addAttribute("role",role);
        return "zhu";
    }
    //tui
    @RequestMapping("tui")
    public String tozhu(){
        List<Role> role=etcService.findRole();

        return "login";
    }
    //addetc
    @RequestMapping("addetc")
    public String addetc(Etc etc,Model model){
        etcService.add(etc);
        return "redirect:/e/toshow1";
    }
    //toshow1
    @RequestMapping("toshow1")
    public String toshow1(Model model){
        List<Etc> dtos=userService.findAll();
        model.addAttribute("dto",dtos);
        return "show1";
    }
    //deleteetc
    @RequestMapping("deleteetc")
    public String deleteetc(Integer id){
etcService.del(id);
        return "redirect:/e/toshow1";
    }
    //toupetc
    @RequestMapping("toupetc")
    public String toupetc(Integer id,Model model){
    Etc etc=   etcService.findOne(id);
        model.addAttribute("dto",etc);
        return "updateEtc";
    }
    //upetc
    @RequestMapping("upetc")
    public String upetc(Etc etc){
        etcService.up(etc);
        return "redirect:/e/toshow1";
    }
}
